<template>
  <TopNav title="患者登记"/>
  <div class="container">
    <van-cell-group class="form">
      <van-field v-model="addFormInfo.patientNumber" label="住院号" placeholder="请填写住院号"/>
      <van-field v-model="addFormInfo.patientName" label="姓名" placeholder="请填写姓名"/>
      <van-field v-model="addFormInfo.patientSex" label="性别" placeholder="请填写性别"/>
      <van-field v-model="addFormInfo.patientAge" label="年龄" placeholder="请填写年龄"/>
      <van-field v-model="addFormInfo.height" label="身高" placeholder="请填写身高"/>
      <van-field v-model="addFormInfo.height" label="体重" placeholder="请填写体重"/>
      <van-field type="textarea" rows="2" v-model="addFormInfo.disease" label="所患疾病" placeholder="请填写"/>
    </van-cell-group>
    <el-button @click="sureHandler()" class="button" type="success" round>确认</el-button>
  </div>
</template>

<script setup>
import patientAxios from "@/api/patient.js"
import {useDataStore} from "@/stores/dataStore.js";
import {reactive} from "vue";
import {useRoute, useRouter} from 'vue-router'
import TopNav from "@/components/TopNav/Back.vue"

const route = useRoute()
const router = useRouter()
const dataStore = useDataStore()
const addFormInfo = reactive({
  patientName: "",
  patientNumber: "",
  patientSex: "",
  patientAge: "",
  height: "",
  weight: "",
  disease: "",
  assessmentDate: "",
  assessmentResult: "",
  patientNRS: "",
  patientMUST: "",
  treatmentStage: "",
})
const sureHandler = () => {
  if (addFormInfo.patientName != ""
      && addFormInfo.patientNumber != ""
      && addFormInfo.patientSex != ""
      && addFormInfo.patientAge != ""
      && addFormInfo.height != ""
      && addFormInfo.weight != ""
      && addFormInfo.disease != "") {
    http_patient_add()
  } else {
    ElMessage.error("请填写完整信息")
  }
}
const http_patient_add = () => {
  patientAxios.patient_add({
    patientName: addFormInfo.patientName,
    patientNumber: addFormInfo.patientNumber,
    patientSex: addFormInfo.patientSex,
    patientAge: addFormInfo.patientAge,
    height: addFormInfo.height,
    weight: addFormInfo.weight,
    disease: addFormInfo.disease,
    assessmentDate: addFormInfo.assessmentDate,
    assessmentResult: addFormInfo.assessmentResult,
    patientNRS: addFormInfo.patientNRS,
    patientMUST: addFormInfo.patientMUST,
    treatmentStage: addFormInfo.treatmentStage,
  }).then(res => {
    if (res.data.code == 200) {
      router.push("/patient/index")
    } else {
      ElMessage.error(res.data.message)
    }
  })
}
</script>

<style scoped lang="scss">
.container {
  background-color: #ffffff;
  height: 700px;
  padding-top: 30px;
}

.form {

}

.button {
  margin-left: 10%;
  width: 80%;
  height: 40px;
}
</style>
